﻿Public Class EditMenu

    Public Sub EditMenu_DropDown(ByVal sender As Object, ByVal e As System.EventArgs)
        MainForm.UndoToolStripMenuItem.Enabled = Not IsNothing(MainForm.EditorTabManager.CurrentTab)
        MainForm.RedoToolStripMenuItem.Enabled = Not IsNothing(MainForm.EditorTabManager.CurrentTab)
        MainForm.CutToolStripMenuItem.Enabled = Not IsNothing(MainForm.EditorTabManager.CurrentTab)
        MainForm.CopyToolStripMenuItem.Enabled = Not IsNothing(MainForm.EditorTabManager.CurrentTab)
        MainForm.PasteToolStripMenuItem.Enabled = Not IsNothing(MainForm.EditorTabManager.CurrentTab)
        MainForm.FindToolStripMenuItem.Enabled = Not IsNothing(MainForm.EditorTabManager.CurrentTab)
        MainForm.ReplaceToolStripMenuItem.Enabled = Not IsNothing(MainForm.EditorTabManager.CurrentTab)
        MainForm.SelectAllToolStripMenuItem.Enabled = Not IsNothing(MainForm.EditorTabManager.CurrentTab)
        MainForm.GoToParentToolStripMenuItem.Enabled = Not IsNothing(MainForm.EditorTabManager.CurrentTab)

        If Not IsNothing(MainForm.EditorTabManager.CurrentTab) Then
            MainForm.UndoToolStripMenuItem.Enabled = MainForm.EditorTabManager.CurrentTab.ScintillaEditor.UndoRedo.CanUndo
            MainForm.RedoToolStripMenuItem.Enabled = MainForm.EditorTabManager.CurrentTab.ScintillaEditor.UndoRedo.CanRedo
            MainForm.PasteToolStripMenuItem.Enabled = MainForm.EditorTabManager.CurrentTab.ScintillaEditor.Clipboard.CanPaste
        End If
    End Sub

    Public Sub UndoToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MainForm.EditorTabManager.CurrentTab.ScintillaEditor.UndoRedo.Undo()
    End Sub

    Public Sub RedoToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MainForm.EditorTabManager.CurrentTab.ScintillaEditor.UndoRedo.Redo()
    End Sub

    Public Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MainForm.EditorTabManager.CurrentTab.ScintillaEditor.Clipboard.Cut()
    End Sub

    Public Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MainForm.EditorTabManager.CurrentTab.ScintillaEditor.Clipboard.Copy()
    End Sub

    Public Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MainForm.EditorTabManager.CurrentTab.ScintillaEditor.Clipboard.Paste()
    End Sub

    Public Sub FindToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Temporary until a find tool is created
        MainForm.EditorTabManager.CurrentTab.ScintillaEditor.FindReplace.ShowFind()
    End Sub

    Public Sub FindFilesToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Public Sub ReplaceToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Temporary until a replace is created
        MainForm.EditorTabManager.CurrentTab.ScintillaEditor.FindReplace.ShowReplace()
    End Sub

    Public Sub ReplaceFilesToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Public Sub SelectAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        MainForm.EditorTabManager.CurrentTab.ScintillaEditor.Selection.SelectAll()
    End Sub

    Public Sub GotoParentClassToolStripMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim completedparsing As Boolean =
            MainForm.EditorTabManager.CurrentTab.ProjectFile.UnrealClass.CompletedParsing
        If completedparsing Then
            Dim unrealclass = MainForm.EditorTabManager.CurrentTab.ProjectFile.UnrealClass
            Dim parentname As String = unrealclass.ParentName
            Dim parentfile = Globals.CurrentProject.FileList.GetProjectFileByClassName(parentname)

            If Not IsNothing(parentfile) Then
                Dim tab = MainForm.EditorTabManager.AddTab(parentfile.FileName, parentfile)
            End If
        End If
    End Sub

End Class
